<link rel="stylesheet" type="text/css" href="<?php echo base_url('skin/css/admin.css');?>">
<?php

$row = array(
    'account_name' => 'Account Name',
    'email' => 'Email',
    'lname' => 'Last Name',
    'fname' => 'First Name',
    'store_name' => 'Store Name',
    'status' => 'Status',
    'name' => 'Permission',
);

$searchable = array(
    'account_name' => 'Account Name',
    'lname' => 'Last Name',
    'fname' => 'First Name',
    'store_name' => 'Store Name',
);

?>
<script type="text/javascript">
var data={};var id=0;
</script>

<div id="user_list tabs-1" class="ui-tabs-panel ui-widget-content ui-corner-bottom" aria-labelledby="ui-id-1" role="tabpanel" aria-hidden="false">
     <script type="text/javascript">
         console.log("messages");
         //var messages = messages || {};
            <?php if ($_success): ?>
                messages['success']="<?php echo $_success; ?>";
            <?php endif; ?>
            <?php if ($_error): ?>
                messages['error']="<?php echo $_error; ?>";
            <?php endif; ?>
        
    </script>
    <form action="<?php site_url('admin/lists')?>" method="POST">
    <table class="borderless">
        <tbody>
            <?php $i=0; foreach($searchable as $field => $label): ?>
           <?php echo (($i%2)==0)? '<tr>':'';?>
               <td><?php echo $label; ?></td>
               <td>
                   <?php if ($field==='store_name'): ?>
                   <select class="searchfield" name="<?php echo $field;?>">
                       <option value="">Select Store</option>
                       <?php foreach($stores as $store): ?>
                       <option value="<?php echo $store->store_name; ?>" <?php echo ($searchinfo[$field]==$store->store_name)?'selected':'';?>><?php echo $store->store_name; ?></option>
                       <?php endforeach;?>
                   </select>
                   <?php else: ?>
                   <input class="searchfield" type="text" placeholder="<?php echo $label; ?>" 
                          name="<?php echo $field; ?>" value="<?php echo isset($searchinfo[$field])?$searchinfo[$field]:''; ?>" />
                   <?php endif; ?>
               </td>
          <?php echo (($i%2)==1)? '</tr>':'';?>
          
          <?php $i++;endforeach; ?>
           <tr>
               <td colspan="4" style="text-align:right; padding:10px;">
                   <input  style="width:200px;" type="submit" name="btn_search" value="Search" />
                   <!--input  style="width:200px;" type="button" name="btn_export" onclick="document.location=&quot;<?php echo site_url('bulk/export')?>&quot;" value="Extract Users" /-->
               </td>
          </tr>
       </tbody>
    </table>
    </form>
    <br />

    <table>
        <thead>
            <tr>
                <th>#</th>
                <?php $link=$link_class=''; 
                foreach($row as $field => $h):?>
                <?php
                    if ($_field==$field){
                        $link = site_url('admin/lists?field='.$field.'&dir='.($_dir==='ASC'?'DESC':'ASC').'&per_page='.$_page);
                        $link_class=($_dir==='ASC'?'sorting_arrow_down':'sorting_arrow_up');
                    }else{
                        $link = site_url('admin/lists?field='.$field.'&dir=ASC&per_page='.$_page);
                        $link_class='sorting_arrow_neutral';
                    }?>
                <th><?php echo $h;?><?php if (isset($searchable[$field])):?>&nbsp;<a href="<?php echo $link?>"><div class="<?php echo $link_class?>"></div></a><?php endif; ?></th>
                <?php endforeach;?>
                <th>Action</th>
            </tr>
        </thead>
  
        <tbody>
            <?php $time =time();$i=(isset($_page)?(int)$_page:0);?> 
            <?php if (isset($users)&& is_array($users) && $users): ?>
           <?php foreach($users as $key => $data) : ?>
            <script type="text/javascript">
                id=<?php echo $data->id; ?>;
                data["id"+id] = {};
            </script>

            <tr<?php echo (($i%2)==0)?' style="background-color: #eee;"':'';?>>
                <td><?php echo $i+1; ?></td>
                <?php $rows = array(); foreach($row as $d => $h):?>
                <td><?php $rows[$d]=$data->$d; echo ($d=='status')?($_status[$data->$d]):($d=='name'?ucfirst($data->$d):$data->$d);?></td>
                <?php endforeach;?>
                <?php 
                $selects = array('shr','smin','ehr','emin');
                foreach($selects as $k => $v){
                    $rows[$v]=$data->$v;
                }
                ?>
                <td>
                    <script type="text/javascript">data["id"+id]=<?php echo json_encode($rows); ?>;</script>
                    <button class="btn_edituser" role="<?php echo $data->rid ?>" data="<?php echo $data->id ?>">Edit</button>
                    <button class="btn_deleteuser" data="<?php echo $data->id ?>">Delete</button>
                    <?php if (($data->locked_expired > time())):?>
                    <button class="btn_unlockuser" href="<?php echo site_url('admin/unlockUser')?>" data="<?php echo $data->id; ?>" s_id="<?php echo $data->session_id;?>">Unlock</button>
                    <?php endif; ?>
                </td>
            </tr>
            <?php $i++; endforeach; ?>
            <?php else: ?>
                <tr><td colspan="<?php echo count($row)+2;?>">No Record Found.</td></tr>
            <?php endif; ?>
        </tbody>
        <?php if (isset($users)&& $users && $pages): ?>
        <tfoot>
            <tr><td colspan="<?php echo count($row)+2;?>"><?php echo $pages; ?></td></tr>
        </tfoot>
        <?php endif; ?>
    </table>
</div>
<div class="clear"></div>
<div class="space" style="margin-bottom: 50px;"></div>
